<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich" template="/template.xhtml">
	<ui:define name="pageTitle">
		<h:outputText styleClass="outputText" id="textPageTitle" value="Add Check-up Survey"></h:outputText>
	</ui:define>
	<ui:define name="pageContent">
		<f:loadBundle var="msg" basename="messages"/>	
		<h:form styleClass="form" id="form1" >
		<script type="text/javascript" src="../resources/js/jquery-1.4.4.min.js"></script>
		<script type="text/javascript" src="../resources/js/jquery-ui-1.8.10.offset.datepicker.min.js"></script>
		<link type="text/css" href="../resources/css/ui-lightness/jquery-ui-1.8.10.custom.css" rel="stylesheet" />
		<script type="text/javascript">
		function doPopupHistory(source) {  
			var url = "#{msg['page.view.history']}?i_answerId=#{packageBean.id}";
			popup = window.open(url,'_blank', 'height=768,width=1024,toolbar=no,menubar=no,scrollbars=yes');  
			popup.focus();  
		} 
		</script>
		<rich:panel>
			<ui:include src="/common/message.xhtml" />
			<f:facet name="header">
				<h:outputText styleClass="outputText" id="textSection" value="โปรแกรมตรวจสุขภาพ"></h:outputText>
			</f:facet>
			<table width="80%" align="center" style="border: 1px solid #777777">
				<tr>
					<td height="30px" style="padding-left: 40px">
						<h:outputLabel value="HN# : "/>
						<h:outputLabel value="#{packageBean.patient.hn}"/>
					</td>
					<td>
						<h:outputLabel value="Name : "/>
						<h:outputLabel value="#{packageBean.patient.name}"/>
					</td>
					<td>
						<h:outputLabel value="Status : "/>
						<h:outputLabel value="#{packageBean.patient.status}"/>
					</td>
				</tr>
				<tr>
					<td height="30px" width="35%" style="padding-left: 40px">
						<h:outputLabel value="Gender : "/>
						<h:outputLabel value="#{packageBean.patient.gender}"/>
					</td>
					<td width="32%">
						<h:outputLabel value="DOB : "/>
						<h:outputLabel value="#{packageBean.patient.DOB}"/>
					</td>
					<td width="33%">
						<h:outputLabel value="Age : "/>
						<h:outputLabel value="#{packageBean.patient.age}"/><h:outputLabel value=" years "/>
					</td>
				</tr>
				<tr>
					<td height="30px" style="padding-left: 40px">
						<h:outputLabel value="Vital Sign(Sys/Dia/Heart Rate) : "/>
						<h:outputLabel value="#{packageBean.patient.SYS}"/><h:outputLabel value="/"/>
						<h:outputLabel value="#{packageBean.patient.DIA}"/><h:outputLabel value="/"/>
						<h:outputLabel value="#{packageBean.patient.heart}"/>
					</td>
					<td width="32%">
						<h:outputLabel value="น้ำหนัก (กก.): "/>
						<h:outputLabel value="#{packageBean.patient.weight}"/><h:outputLabel value="  "/>
						<h:outputLabel value="ส่วนสูง (ซม.): "/>
						<h:outputLabel value="#{packageBean.patient.height}"/><h:outputLabel value="  "/>
						<h:outputLabel value="BMI : "/>
						<h:outputLabel value="#{packageBean.patient.BMI}"/>
					</td>
					<td width="33%">
						<h:outputLabel value="Visit Date : "/>
						<h:outputLabel value="#{packageBean.patient.visitDateStr}"/>
					</td>		
				</tr>
			</table>
			<br/>
			<table id="tblResult" width="80%" align="center" cellpadding="2" cellspacing="0">
				<tr>
					<td>	
					<rich:dataTable border="1" cellpadding="0" cellspacing="0" 
						columnClasses="columnClassCenter, columnClassLeft, columnClassLeft, columnClassLeft, columnClassRight,columnClassCenter" 
						headerClass="headerClass" footerClass="footerClass" rowClasses="rowClass1, rowClass2" styleClass="dataTable"
						id="table" style="width:100%" value="#{packageBean.patient.packageList}" var="varitems" >
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Select"/>
							</f:facet>
							<h:selectBooleanCheckbox value="#{packageBean.checked[varitems.id]}" disabled="true" rendered="#{packageBean.freezeFlag == 'Y'}" />
							<h:selectBooleanCheckbox value="#{packageBean.checked[varitems.id]}" rendered="#{packageBean.freezeFlag == 'N'}">
								<a4j:ajax event="click" execute="table" listener="#{packageBean.selectPackage}" render="table" />							
							</h:selectBooleanCheckbox>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Package" />
							</f:facet>
							<h:outputText value="#{varitems.packageName}" />
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{varitems.descriptionHtml}" escape="false"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Indication" />
							</f:facet>
							<h:outputText value="#{varitems.indicationHtml}" escape="false"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Price" />
							</f:facet>
							<h:outputText value="#{varitems.price}" rendered="#{(varitems.otherFlag=='N' || varitems.otherFlag=='S')}">
								<f:convertNumber pattern="###,###,##0.00"/>
							</h:outputText>
							<h:outputText value="#{packageBean.otherPrice}" size="10" styleClass="iDL" readonly="true" rendered="#{packageBean.freezeFlag == 'Y' and varitems.otherFlag == 'Y'}">
								<f:convertNumber pattern="###,###,##0.00"/>
							</h:outputText>

							<h:inputText value="#{packageBean.otherPrice}" size="10" styleClass="iNL" rendered="#{packageBean.freezeFlag == 'N' and (varitems.otherFlag == 'Y' and packageBean.checked[varitems.id])}" style="text-align:right;">
								<a4j:ajax event="change" execute="table" listener="#{packageBean.selectPackage}" render="table" />
								<f:convertNumber pattern="###,###,##0.00"/>					
							</h:inputText>

							<h:inputText value="#{packageBean.otherPrice}" size="10" styleClass="iDL" readonly="true" rendered="#{packageBean.freezeFlag == 'N' and varitems.otherFlag == 'Y' and !packageBean.checked[varitems.id].booleanValue()}" style="text-align:right;">
								<f:convertNumber pattern="###,###,##0.00"/>					
							</h:inputText>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="Remark" />
							</f:facet>							
							<h:inputText value="#{packageBean.remarks[varitems.id]}" styleClass="iDL" readonly="true" rendered="#{packageBean.freezeFlag == 'Y' and (varitems.otherFlag=='N' || varitems.otherFlag=='S')}"/>

							<h:inputTextarea value="#{packageBean.otherRemark}" rows="10" cols="20" styleClass="iDL" readonly="true" rendered="#{packageBean.freezeFlag == 'Y' and varitems.otherFlag == 'Y'}"/>

							<h:inputText value="#{packageBean.remarks[varitems.id]}" styleClass="iNL" rendered="#{packageBean.freezeFlag == 'N' and ((varitems.otherFlag=='N' || varitems.otherFlag=='S') and packageBean.checked[varitems.id])}"/>
							<h:inputText value="#{packageBean.remarks[varitems.id]}" styleClass="iDL" readonly="true" rendered="#{packageBean.freezeFlag == 'N' and (varitems.otherFlag=='N' || varitems.otherFlag=='S') and !packageBean.checked[varitems.id].booleanValue()}"/>

							<h:inputTextarea value="#{packageBean.otherRemark}" rows="10" cols="20" styleClass="iNL" rendered="#{packageBean.freezeFlag == 'N' and (varitems.otherFlag == 'Y' and packageBean.checked[varitems.id])}"/>
							<h:inputTextarea value="#{packageBean.otherRemark}" rows="10" cols="20" styleClass="iDL" readonly="true" rendered="#{packageBean.freezeFlag == 'N' and varitems.otherFlag == 'Y' and !packageBean.checked[varitems.id].booleanValue()}"/>
						</rich:column>
						
				        <f:facet name="footer">
				            <rich:columnGroup>
				                <rich:column colspan="4">Totals</rich:column>
				                <rich:column>
				                    <h:outputText value="#{packageBean.patient.totalPrice}">
				                    	<f:convertNumber pattern="#,##0.00" />
				                    </h:outputText>
									<h:inputHidden id="totalPrice" value="#{packageBean.patient.totalPrice}" >
										<f:convertNumber pattern="#,##0.00" />
									</h:inputHidden>	
				                </rich:column>
				                <rich:column>
				                    <h:outputText value=" "/>
				                </rich:column>
				            </rich:columnGroup>
				        </f:facet>						
					</rich:dataTable>	
					</td>
				</tr>	
			</table>
			<br/>
			<table width="80%" align="center" style="border: 1px dashed #777777">
				<tr>
					<td colspan="2" height="45px" style="padding-left: 15px">
						<b><h:outputText value="Risk Factor Summary"/></b>
					</td>
				</tr>
				<tr>
					<td width="35px"></td>
					<td>
						<h:outputText value="#{packageBean.patient.riskFactoryHtml}" escape="false"/>
					</td>
				</tr>
				<tr>
					<td colspan="2" height="40px" style="padding-left: 15px; padding-top: 10px">
						<b><h:outputText value="หมายเหตุ :"/></b>
					</td>
				</tr>
				<tr>
					<td></td>
					<td style="padding-bottom: 10px">
						<h:outputText value="รายการนี้เป็นราคาพิเศษสำหรับผู้เข้ารับการตรวจสุขภาพที่โรงพยาบาลสมิติเวชศรีราชา ท่านสามารถใช้สิทธิตรวจได้ถึง ..................."/>
					</td>
				</tr>
				<tr>
					<td></td>
					<td style="padding-bottom: 10px">
						<h:inputText value="#{packageBean.patient.note}" styleClass="iNL" size="100" readonly="true" rendered="#{packageBean.freezeFlag == 'Y'}"/>
						<h:inputText id="note" value="#{packageBean.patient.note}" styleClass="iNL" size="100" rendered="#{packageBean.freezeFlag == 'N'}"/>
					</td>
				</tr>
				<tr><td colspan="2"><h:outputText value="          "/></td></tr>
				<tr>
					<td></td>
					<td style="padding-bottom: 30px">
						<table width="100%">
							<tr>
								<td>
									<h:outputText value="ผู้ให้การแนะนำ"/>
									<h:outputText value="...................     "/>
								</td>
								<td width="150px"><h:outputText value="          "/></td>
								<td>
									<h:outputText value="ผู้รับการรักษา"/>
									<h:outputText value="...................     "/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<br/>		
			<table width="80%" align="center" style="background-color: #DDDDDD; border: 1px solid #AAAAAA">
			<tr>
				<td height="45px" align="center">					
					<h:commandButton value="ประวัติสุขภาพ" styleClass="btn-command" onclick="doPopupHistory(this);return false;"/>
					<h:outputLabel value="     " styleClass="outputLabel" />
					
					<h:commandButton value="Buy" styleClass="btn-command" action="#{packageBean.create}" disabled="true" rendered="#{packageBean.freezeFlag == 'Y'}"/>
					<h:commandButton type="submit" styleClass="btn-command" id="buttonSave" value="Buy" title="Buy" action="#{packageBean.create}" rendered="#{packageBean.freezeFlag == 'N'}"/>

					<h:outputLabel value="     " styleClass="outputLabel" />
					<h:commandButton value="Cancel" styleClass="btn-command" action="#{packageBean.cancel}" disabled="true" rendered="#{packageBean.patient.status != 'Buy' and packageBean.patient.status != 'Estimate'}"/>
					<h:commandButton type="submit" styleClass="btn-command" id="buttonCancel" value="Cancel" title="Cancel" action="#{packageBean.cancel}" immediate="true" rendered="#{packageBean.patient.status == 'Buy' || packageBean.patient.status == 'Estimate'}"/>

					<h:outputLabel value="     " styleClass="outputLabel" />
					<h:commandButton type="submit" styleClass="btn-command" id="buttonPrint" value="Print" title="Print" action="#{packageBean.print}" />

					<h:outputLabel value="     " styleClass="outputLabel" />
					<h:commandButton type="submit" styleClass="btn-command" id="buttonClose" value="Close" title="Close" action="#{packageBean.close}" immediate="true" />
				</td>
			</tr>
			</table>
		</rich:panel>
		</h:form>		
	</ui:define>	
</ui:composition>